<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateDelayOrderTaskTable extends AbstractMigration
{
    public function up()
    {
        $table = $this->table('delay_order_task', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '延期单任务']);
        $table->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID'])
            ->addColumn('uuid', 'char', ['default' => '', 'limit' => 36, 'comment' => '全局唯一标识符'])
            ->addColumn('delay_order_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '延期单id'])
            ->addColumn('type', 'enum', ['values' => 'request_delay,today_done', 'default' => 'request_delay', 'comment' => '延期任务类型(申请延期 request_delay, 今日完成 today_done)'])
            ->addColumn('project_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '项目id'])
            ->addColumn('task_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '任务id'])
            ->addColumn('original_plan_time', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '原计划完成时间'])
            ->addColumn('plan_delivery_time', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '原计划交付时间'])
            ->addColumn('delay_time', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '申请延期时间'])
            ->addColumn('abnormal_info', 'string', ['null' => false, 'default' => '', 'limit' => 20, 'comment' => '异常情况(not_done 未完成,not_delivery 未交付)'])
            ->addColumn('delay_reason', 'text', ['null' => true, 'comment' => '延期原因'])
            ->addColumn('created_by', 'integer', ['signed' => false, 'null' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建人'])
            ->addColumn('created', 'integer', ['signed' => false, 'null' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建时间']);
        // 创建表
        $table->create();
    }

    public function down()
    {
        $this->table('delay_order_task')->drop()->save();
    }
}
